<?php
/**
 * 用户
 *
 *
 */


class deliveraddress_model extends CI_Model
{
	const tableName = "deliveraddress";

    var $id;
    
	var $fullAddress;

	var $phone;
	
	var $phoneOptional;

	var $isDefault;

	var $userId;

	function __construct()
    {
        parent::__construct();
    }

	// --------------------------------------------------------------------

    /**
     * 
     * 插入deliveraddress数据
     */
 	function insert_entry($data)
    {
    	$this->name   = $data['name'];
        $this->fullAddress   = $data['fullAddress'];//完整地址
        $this->phone = $data['phone'];//电话
        //$this->phoneOptional   = $data['phoneOptional']; //备选电话
        $this->isDefault = $data['isDefault'];//默认地址
        $this->userId = $data['userId'];//用户Id

        $this->db->insert(self::tableName, $this);
    }
    

    /**
     * 
     * Enter description here ...
     * @param unknown_type $deliverAddressId
     * @param unknown_type $userId
     */
    function delete_address_by_id_and_user_id($deliverAddressId, $userId){
    	$sql = "DELETE FROM ".self::tableName." WHERE id = ? AND userId= ?"; 
		$this->db->query($sql, array($deliverAddressId,$userId));
    }
    /**
	 * load by id
	 *
	 *
	 */	
    function load($id)
    {
        if (!$id){
            return array();
        }

        $query = $this->db->get_where('deliveraddress',array('id' => $id));

        if ($row = $query->row_array()){
            return $row;
        }

        return array();
    }
    
    
    /**
	 * load by id
	 *
	 *
	 */	
    function getAddressByUserid($userid)
    {
        if (!$userid){
            return array();
        }

        $query = $this->db->get_where('deliveraddress',array('userid' => $userid));

        return $query->result();
    }
    
}